
import {LGXEnums}  from '../../../common/sysenum.js';

import snapsvc from '../../../service/pointsnapsvc.js'
var svc = snapsvc.PointSnapSvc;

import polyposgraphsnapsvc from '../../../service/polyposgraphsnapsvc.js';

var MosMovePlotTool = {

}

MosMovePlotTool.action = function (dataManger, mosEvnt, worldPos) {
    var pCurentGraph = dataManger.getCurentGraph();
    if (pCurentGraph){
        dataManger.recordRepaintScope(pCurentGraph);
    }
    let absorbFlag = svc.snapMouse2OtherGraphPTFeature(dataManger, worldPos,false,false);
    if (!absorbFlag && this.chkPolyGraphInPlotting(pCurentGraph)) {
        //正在绘制，但是没有绘制玩的线路或多边形，
        //需要判断当前点与前面点组成的线段是否能与周边的其他线段平行或者垂直，或者尺寸相等
        let t0 = +new Date(); 
        polyposgraphsnapsvc.PolyposGraphSnapSvc.absorb(pCurentGraph,dataManger,worldPos);
        let t1 = +new Date(); 
        // console.log("MosMovePlotTool.action timeelapse:" + (t1-t0));
    }
    if (pCurentGraph != null
        && pCurentGraph.getStart() == 1
        && pCurentGraph.getUseful() == 1
        && pCurentGraph.getFinish() == 0) {
        pCurentGraph.act2Mouse(mosEvnt, worldPos);
    }
    if (pCurentGraph){
        dataManger.recordRepaintScope(pCurentGraph);
    }
}

MosMovePlotTool.chkPolyGraphInPlotting = function(pCurentGraph){
    if (!pCurentGraph) {
        return false;
    }
    let type = pCurentGraph.m_graphType;
    if (type != LGXEnums.LGXGraphType.LineGraph_type
        && type != LGXEnums.LGXGraphType.PolygonGraph_type) {
        return false;
    }
    if (pCurentGraph.getStart() == 0
        || pCurentGraph.getFinish() == 1) {
        return false;
    }
    return true;
}

export default { MosMovePlotTool }